package com.taptech.doufu.services;

import android.content.Context;
import android.content.Intent;

import com.taptech.doufu.ui.activity.BrowseActivity;
import com.taptech.doufu.ui.activity.CartoonEpisodeMenuActivity;
import com.taptech.doufu.ui.activity.CartoonScanNewActivity;
import com.taptech.doufu.ui.activity.EasyBrowseActivity;
import com.taptech.doufu.ui.activity.weex.SimpleWeexActivity;
import com.taptech.doufu.constant.FragmentLoadType;
import com.taptech.doufu.constant.IntentKey;
import com.taptech.doufu.bean.AlbumsBean;
import com.taptech.doufu.bean.cartoon.CartoonBean;
import com.taptech.doufu.bean.cartoon.WholeCartoonDetaisBean;
import com.taptech.doufu.constant.Constant;
import com.taptech.doufu.util.StartActivityUtil;
import com.taptech.doufu.util.StartActivityUtils;

import java.util.HashMap;

/**
 * Created by longsiyang on 15/12/11.
 */
public class CartoonServices extends BaseService  {

    public static final String BASE_URL = "http://" + Constant.HOST_NAME
            + "/index.php/";

    public static final int HANDLE_TYPE_LOAD_CARTOON  = 1001;
    public static final int HANDLE_TYPE_LOAD_CARTOON_DETAIL2 = 11002;
    public static final int HANDLE_TYPE_LOAD_CARTOON_RECOMMEND = 1003;
    public static final int HANDLE_TYPE_PAY_CARTOON = 1004;

    private static CartoonServices instance = new CartoonServices();
    private CartoonServices() {
    }

    public static CartoonServices getInstance() {
        return instance;
    }


    /**
     * 点击更多按钮
     * @param context
     * @param url
     * @param name
     */
    public static void clickMore(Context context,String url, String name) {
        Intent intent=new Intent();
        intent.putExtra(Constant.URL,url);
        intent.putExtra(FragmentLoadType.fragmentTypeName,name);
        intent.putExtra(FragmentLoadType.fragmentType,FragmentLoadType.RECOMMENDMORE);
        new StartActivityUtils(context,intent).toCarttonSortDesActivity();
    }

    public static void clickMore(Context context,String url, String name,int coverType) {
        Intent intent=new Intent();
        intent.putExtra(Constant.URL,url);
        intent.putExtra(IntentKey.INTENT_KEY_COVER_TYPE, coverType);
        intent.putExtra(FragmentLoadType.fragmentTypeName,name);
        intent.putExtra(FragmentLoadType.fragmentType,FragmentLoadType.RECOMMENDMORE);
        new StartActivityUtils(context,intent).toCarttonSortDesActivity();
    }

    /**
     * 点击漫画卡片跳转
     * @param mContext
     * @param id
     * @param object_type
     * @param targetUrl
     * @param title
     */
    public static void clickContentCard(Context mContext,
                                        String id,
                                        int object_type,
                                        String targetUrl,
                                        String title) {
        Intent intent = new Intent();

        switch (object_type) {
            case Constant.OBJECT_TYPE_CARTOON:
                CartoonServices.enterCartoonDes(mContext, id);
                break;
            case Constant.OBJECT_TYPE_ALBUMS:
                AlbumsBean albumsBean = new AlbumsBean();
                albumsBean.setName(title);
                albumsBean.setUrl(targetUrl);
                StartActivityUtil.albumsOnclick(mContext, albumsBean);
                break;
            case Constant.OBJECT_TYPE_BROWSE:// 跳转到内部网页的类型
                intent.setClass(mContext, BrowseActivity.class);
                intent.putExtra(Constant.URL, targetUrl);
                intent.putExtra(Constant.TITLE, title);
                mContext.startActivity(intent);
                break;
            case Constant.OBJECT_TYPE_EASY_WEBVIEW:
                intent.setClass(mContext, EasyBrowseActivity.class);
                intent.putExtra(Constant.URL, targetUrl);
                intent.putExtra(Constant.TITLE, title);
                mContext.startActivity(intent);
                break;
            case Constant.OBJECT_TYPE_WEEX:
                SimpleWeexActivity.startActivity(mContext,targetUrl);
                break;

            default:
                if(targetUrl.contains("/weex/")){
                    SimpleWeexActivity.startActivity(mContext,targetUrl);
                }
                break;

        }
    }

    static public void enterCartoonDes(Context context , String id){
        HashMap<String, String> map = new HashMap<>();
        map.put("id", id);
        map.put("object_type", String.valueOf(Constant.OBJECT_TYPE_CARTOON));
        SimpleWeexActivity.startActivity(context,"TFNovel/TFComicDetail.js?id="+id,map);
    }

    static public void enterCartoonDes(Context context , String id,int flag){
        HashMap<String, String> map = new HashMap<>();
        map.put("id", id);
        map.put("object_type", String.valueOf(Constant.OBJECT_TYPE_CARTOON));
        SimpleWeexActivity.startActivity(context,"TFNovel/TFComicDetail.js?id="+id,map,flag);
    }

    static public void enterCartoonDes(Context context , CartoonBean bean){
        HashMap<String, String> map = new HashMap<>();
        map.put("id", bean.getId());
        map.put("object_type", String.valueOf(Constant.OBJECT_TYPE_CARTOON));
        SimpleWeexActivity.startActivity(context,"TFNovel/TFComicDetail.js?id="+bean.getId(),null);
    }


    //目录跳转使用
    static public void enterCartoonScanNewActivity(Context context , WholeCartoonDetaisBean bean , int position){
        Intent intent = new Intent(context , CartoonScanNewActivity.class);
        if (bean != null && bean.getDetail() != null) {
            intent.putExtra(Constant.CARTOON_ID , bean.getDetail().getId());
        }
        intent.putExtra(Constant.POSITION , position);
        context.startActivity(intent);
    }

    //首页漫画跳转最新专用
    static public void enterCartoonScanNewActivity(Context context , String cartoonId , int position, boolean flag){
        Intent intent = new Intent(context , CartoonScanNewActivity.class);
        intent.putExtra(Constant.IS_NEWSTCARTOON,flag);
        intent.putExtra(Constant.CARTOON_ID , cartoonId);
        intent.putExtra(Constant.POSITION , position);
        context.startActivity(intent);
    }

    static public void enterCartoonScanNewActivity(Context context , String cartoonId , int position, boolean flag,int intentFlag){
        Intent intent = new Intent(context , CartoonScanNewActivity.class);
        intent.putExtra(Constant.IS_NEWSTCARTOON,flag);
        intent.putExtra(Constant.CARTOON_ID , cartoonId);
        intent.putExtra(Constant.POSITION , position);
        intent.setFlags(intentFlag);
        context.startActivity(intent);
    }

    static public void enterCartoonEpisodeMenu(Context context , WholeCartoonDetaisBean bean){
        Intent intent = new Intent(context , CartoonEpisodeMenuActivity.class);
        if (bean != null && bean.getDetail() != null) {
            intent.putExtra(Constant.CARTOON_ID , bean.getDetail().getId());
        }
        context.startActivity(intent);
    }

    static public void enterCartoonEpisodeMenu(Context context , String id){
        Intent intent = new Intent(context , CartoonEpisodeMenuActivity.class);
        intent.putExtra(Constant.CARTOON_ID , id);
        context.startActivity(intent);
    }

}
